<template>

	<view class="DetailView">
		<view class="content">
			<z-paging ref="paging" :refresher-only="true" :fixed="true" :show-loading-more-no-more-view='false'
				:refresher-enabled="false" :refresher-threshold="0" hide-refresher-when-reload
				hide-refresher-when-enabled>
				<template #top>
					<m-drag-button :style="{ opacity: BtnShow ? 1 : 0, }" :isDock="true" :existTabBar="true"
						:initialBottom="160" @btnClick="scan">
						<template #BtnContent>
							<u-icon name="scan" color="#fff" size="54rpx"></u-icon>
						</template>
					</m-drag-button>

					<u-navbar :fixed="false" title="设备维修" :autoBack="true" :safeAreaInsetTop="true"
						@leftClick='leftClick' leftIconColor="#fff"></u-navbar>
				</template>

				<view class="MainBox">
					<u--form labelPosition="left" :model="baseFormData" :rules="rules" ref="uForm">

						<u-cell icon="list-dot" title="申请人填写" style='background-color: #eee;'></u-cell>
						<u-form-item labelWidth="100" label="设备" borderBottom required leftIcon="file-text"
							prop="EquipmentName" :leftIconStyle="{'font-size':'20px'}"
							@click="openBaseScreen('设备','radio')">
							<u--input v-model="baseFormData.EquipmentName" placeholder="请选择设备" readonly
								border="none"></u--input>
							<u-icon slot="right" name="arrow-right"></u-icon>
						</u-form-item>
						<u-form-item labelWidth="100" label="申请人" borderBottom leftIcon="order"
							:leftIconStyle="{'font-size':'20px'}">
							<u--input v-model="baseFormData.ApplyForMan" placeholder="自动生成" readonly
								border="none"></u--input>
						</u-form-item>
						<u-form-item labelWidth="100" label="申请时间" borderBottom leftIcon="calendar"
							:leftIconStyle="{'font-size':'20px'}">
							<u--input v-model="baseFormData.ApplyForTime" placeholder="自动生成" readonly
								border="none"></u--input>
						</u-form-item>
						<!-- #f6f7fb -->
						<u-form-item labelWidth="100" label="故障描述" leftIcon="file-text" required prop="BXContent"
							borderBottom :leftIconStyle="{'font-size':'20px'}">
							<!-- 		<u--input v-model="baseFormData.BXContent" placeholder="请输入故障描述" border="none"
								:readonly="!buttonShow"></u--input> -->
							<u--textarea v-model="baseFormData.BXContent" placeholder="请输入故障描述" border="none" autoHeight
								:style="{backgroundColor:!buttonShow?'#fff':''}" :disabled="!buttonShow"
								style="padding: 0;"></u--textarea>


						</u-form-item>
						<!-- <u-form-item labelWidth="100" label="故障描述" leftIcon="photo"
							:leftIconStyle="{'font-size':'20px'}">
							<u-upload :fileList="DImgs" @afterRead="afterRead" @delete="deletePic" multiple
								:maxCount="5" :previewFullImage="true"></u-upload>
						</u-form-item> -->

						<u-cell icon="list-dot" v-show="buttonTitle!='保存'" title="维修人填写"
							style='background-color: #eee;'></u-cell>
						<u-form-item labelWidth="100" label="维修编号" borderBottom leftIcon="order"
							v-show="buttonTitle!='保存'" :leftIconStyle="{'font-size':'20px'}">
							<u--input v-model="baseFormData.BillNO" placeholder="自动生成" readonly
								border="none"></u--input>
						</u-form-item>
						<u-form-item labelWidth="100" label="维修人" borderBottom leftIcon="file-text"
							v-show="buttonTitle!='保存'" :prop="buttonTitle == '开始维修'?'MaintainMan':''" required
							:leftIconStyle="{'font-size':'20px'}" @click="openBaseScreen('维修人员','radio')">
							<u--input v-model="baseFormData.MaintainMan" placeholder="请选择人员" readonly border="none"
								required></u--input>
							<u-icon slot="right" name="arrow-right"></u-icon>
						</u-form-item>
						<u-form-item labelWidth="100" label="维修内容" borderBottom leftIcon="file-text" required
							v-show="buttonTitle!='保存'" :prop="buttonTitle == '开始维修'?'GZCause':''"
							:leftIconStyle="{'font-size':'20px'}">
							<!-- 		<u--input v-model="baseFormData.GZCause" placeholder="请输入维修内容" border="none"
								:readonly="!buttonShow"></u--input> -->

							<u--textarea v-model="baseFormData.GZCause" placeholder="请输入维修内容" border="none" autoHeight
								:style="{backgroundColor:!buttonShow?'#fff':''}" :disabled="!buttonShow"
								style="padding: 0;"></u--textarea>

						</u-form-item>
						<u-form-item labelWidth="100" label="维修方式" borderBottom leftIcon="file-text"
							v-show="buttonTitle!='保存'" :prop="buttonTitle == '开始维修'?'WayName':''" required
							:leftIconStyle="{'font-size':'20px'}" @click="addWay('WXFS')">
							<u--input v-model="baseFormData.WayName" placeholder="请选择维修方式" border="none"
								readonly></u--input>
							<u-icon slot="right" name="arrow-right"></u-icon>
						</u-form-item>
						<u-form-item labelWidth="100" label="维修费用" borderBottom leftIcon="coupon"
							v-show="buttonTitle!='保存'" :prop="buttonTitle == '结束维修'?'Cost':''"
							:required='buttonTitle == "结束维修"'
							:leftIconStyle="{'font-size':'20px','color':buttonTitle == '开始维修'?'#999999':'#000'}">
							<u--input v-model="baseFormData.Cost"
								:placeholder="buttonTitle == '结束维修' ?'请输入维修费用':'请在结束时填写'" type='number' border="none"
								:readonly="!buttonShow|| buttonTitle == '开始维修'"></u--input>
						</u-form-item>

						<u-form-item labelWidth="100" label="维修状态" borderBottom leftIcon="order"
							v-show="buttonTitle!='保存'" :leftIconStyle="{'font-size':'20px'}">
							<u--input v-model="baseFormData.MaintenanceStatusName" placeholder="自动带出维修状态" border="none"
								readonly></u--input>

						</u-form-item>

						<u-form-item labelWidth="100" label="维修结果" borderBottom leftIcon="file-text"
							:prop="buttonTitle == '结束维修'?'FResultName':''" v-show="buttonTitle!='保存'"
							:required='buttonTitle == "结束维修"'
							:leftIconStyle="{'font-size':'20px','color':buttonTitle == '开始维修'?'#999999':'#000'}"
							@click="addWay1('SBWX')">
							<u--input v-model="baseFormData.FResultName"
								:placeholder="buttonTitle == '结束维修' ?'请选择维修结果':'请在结束时填写'" border="none"
								readonly></u--input>
							<u-icon slot="right" name="arrow-right"></u-icon>
						</u-form-item>
						<u-form-item labelWidth="100" label="开始时间" borderBottom leftIcon="calendar"
							v-show="buttonTitle!='保存'" :leftIconStyle="{'font-size':'20px'}">
							<u--input v-model="baseFormData.BeginTime" placeholder="自动带出开始时间" readonly
								border="none"></u--input>
						</u-form-item>
						<u-form-item labelWidth="100" label="结束时间" leftIcon="calendar" v-show="buttonTitle!='保存'"
							:leftIconStyle="{'font-size':'20px'}">
							<u--input v-model="baseFormData.WCTime" placeholder="自动带出结束时间" readonly
								border="none"></u--input>
						</u-form-item>
					</u--form>
					<!-- 	<view class="buttonView">
						<button size="mini" class="buttonstyle" @click="addplus()">新增配件</button>
					</view> -->

					<view class="AddBottomBox">

						<button class="CancelBtn" :disabled='!buttonShow' size='mini' @click="addplus()">新增配件</button>
					</view>


					<view class="Main_CardListBox">
						<view class="CardBox" v-for="(item,index) in tableData" :key="index">
							<view class="Main_Card_Top">
								<view class="Main_Card_LeftBox x-f">
									<view class="OrdinalBox">
										<text>{{index + 1}}</text>
									</view>
									<view class="Title_Text x-f">
										<!-- <text>保养项目</text> -->
									</view>
								</view>

								<view class="Main_Card_RightBox">
									<view class="TypeText">
										<uni-icons type="trash" size="30" @click="trash(index)"
											color='#828282'></uni-icons>
									</view>
								</view>
							</view>
							<view class="CommonBox">
								<u-cell title="配件名称" icon="file-text" :isLink="true" class="custom-cell"
									@click="addproducplname(item,index)">
									<template #value>
										<div class="CommonBoxDiv" :style="{ width: scrollLiftWidth + 'px'}">
											{{item.ProductPJName}}
										</div>
									</template>
								</u-cell>
								<u-cell title="数量" icon="coupon" :border='false' class="custom-cell">
									<template #value>
										<u--input v-model="item.Num" type='number' border="none"
											inputAlign='left'></u--input>
									</template>
								</u-cell>
							</view>

						</view>
					</view>
				</view>
				<template #bottom>
					<view class="BottomBox" :style="$utils.disposeSafeBottomFun()" v-show="buttonShow">
						<button block @click="submit" style="width: 90%;margin: 0 auto !important;"
							class="content_bottom_primary_Btn">
							{{buttonTitle}}
						</button>
					</view>

				</template>
			</z-paging>


		</view>
		<u-toast ref="uToast"></u-toast>

		<u-action-sheet :actions="StateList" :show="StateShow" @select="StateClick"
			@close="StateShow=false"></u-action-sheet>
		<m-pda-scancode v-if="$utils.isPda()" listenName="BatchEditScan"
			:SetContent="{action:$store.state.systemConfig.sysDeviceInfo.broadcastAction,extra:$store.state.systemConfig.sysDeviceInfo.broadcastResult}"></m-pda-scancode>
	</view>


</template>

<script>
	import {
		formatDateTime,
		getTimeStamp,
		getFormatDateTime,
		getBefore7DateTime
	} from '@/st_device/common/base.js';
	import BaseMixin from '@/st_device/common/base.js';
	export default {
		mixins: [BaseMixin],
		data() {
			return {


				BtnShow: false, // 搜索按钮判断显示

				rules: {

					'EquipmentName': {
						type: 'string',
						required: true,
						message: '设备不能为空',
						trigger: ['change']
					},
					'BXContent': {
						type: 'string',
						required: true,
						message: '故障描述不能为空',
						trigger: ['change']
					},
					'MaintainMan': {
						type: 'string',
						required: true,
						message: '人员不能为空',
						trigger: ['change']
					},
					'GZCause': {
						type: 'string',
						required: true,
						message: '维修内容不能为空',
						trigger: ['blur', 'change']
					},
					'WayName': {
						type: 'string',
						required: true,
						message: '维修方式不能为空',
						trigger: ['change']
					},
					'Cost': {
						type: 'number',
						required: true,
						message: '维修费用不能为空',
						trigger: ['blur', 'change']
					},
					'FResultName': {
						type: 'string',
						required: true,
						message: '维修结果不能为空',
						trigger: ['change']
					}
				},
				// 图标储存数组
				DImgs: [],

				baseFormData: {
					EquipmentName: '',
					ApplyForMan: '',
					ApplyForTime: '',
					BXContent: '',
					BillNO: '',
					MaintainMan: '',
					GZCause: '',
					Way: '',
					WayName: '',
					Cost: '',
					WCStatus: '',
					FResult: 0,
					FResultName: '',
					BeginTime: '',
					WCTime: '',
					BillDate: '',
					MaintenanceStatus: null,
					MaintenanceStatusName: null
				},

				buttonShow: true, //提交按钮是否显示
				buttonTitle: '保存', //提交按钮名称
				tableData: [], //子表数组

				StateShow: false, //维修方式和维修结果 筛选显示
				StateList: [], //维修方式和维修结果数组

				MJWXSList: [], //维修状态列表
				SBWXList: [], //维修结果列表
				WXFSList: [], //维修方法列表


				popup_logout: false, //提示框显示
				popuptitle: '', //提示框标题
				popupcontent: '', //提示框内容
				scrollLiftWidth: uni.getSystemInfoSync().windowWidth, //列表宽度
			};
		},
		onLoad(item) {
			var that = this
			that.initData()
			var EquipmentObj
			// 判断是否是详情页面扫码 传递对象
			if (item.EquipmentObj) {
				EquipmentObj = JSON.parse(item.EquipmentObj)
			}

			// 判断是否有主键id
			if (item.MaintainEquipmentID) {
				that.queryList(item.MaintainEquipmentID)
			} else {
				if (item.item) {
					var item = JSON.parse(item.item)
					this.baseFormData = item
					this.baseFormData.BXContent = item.FaultName + ':' + item.GZContent
				}
				// 申请人名称
				this.baseFormData.ApplyForMan = this.baseFormData.ApplyForMan ? this.baseFormData.ApplyForMan : this
					.$store.state.UserInfo.UserName
				// 申请人id
				this.baseFormData.CheckupID = this.baseFormData.CheckupID ? this.baseFormData.CheckupID : this.$store
					.state.UserInfo.EmplID
				// 如果有扫码传递来的对象 进行赋值
				if (EquipmentObj) {
					this.baseFormData.EquipmentName = this.baseFormData.EquipmentName ? this.baseFormData.EquipmentName :
						EquipmentObj.EquipmentName
					this.baseFormData.EquipmentID = this.baseFormData.EquipmentID ? this.baseFormData.EquipmentID :
						EquipmentObj.EquipmentID
				}
				// 申请人时间
				this.baseFormData.ApplyForTime = this.baseFormData.ApplyForTime ? this.baseFormData.ApplyForTime :
					getFormatDateTime(new Date())
				this.baseFormData.BillDate = this.baseFormData.BillDate ? this.baseFormData.BillDate :
					getFormatDateTime(new Date())

			}
		},
		onBackPress(options) { // 监听页面返回
			if (options.from == 'navigateBack') { // 通过点击路由返回
				return false;
			} else if (options.from == 'backbutton') { // 通过外置返回
				return true;
			}
		},
		onUnload() { // 监听页面卸载,1
			uni.$off('BatchEditScan');
			uni.$off('devicerepairDetail_Choice');
		},
		mounted() {
			var that = this;
			uni.$on('devicerepairDetail_Choice', function(ret) {
				console.log(JSON.stringify(ret))
				if (ret.type == '维修人员') {
					that.baseFormData.MaintainMan = ret.data.EmplName
					that.$refs.uForm.validateField('MaintainMan');
				} else if (ret.type == '配件') {
					that.tableData[that.producplnameIndex].ProductPJID = ret.data.ProductPJID
					that.tableData[that.producplnameIndex].ProductPJName = ret.data.ProductPJName
				} else if (ret.type == '设备') {
					that.baseFormData.EquipmentName = ret.data.EquipmentName
					that.baseFormData.EquipmentID = ret.data.EquipmentID
					that.$refs.uForm.validateField('EquipmentName');
				}
			});
			// PDA扫码处理
			uni.$on('BatchEditScan', function(content) {
				let scanData = that.$utils.wmsFun.scanTransf(content);
				that.scanHandler(scanData);
			})
			that.$nextTick(() => {
				that.scrollLiftWidth = (uni.getSystemInfoSync().windowWidth) / 3
				setTimeout(() => {
					that.BtnShow = true;
				}, 500)
			})
		},
		onShow() {

		},
		methods: {
			async initData() {
				// 加载公共字典数据
				await this.loadCommonDictionaries([{
						type: 'MJWXS', //维修状态
						key: 'MJWXSList',
						cmd: 'MJ_Dictionary',
						obj: {
							FType: 'MJWXS'
						}
					},
					{
						type: 'SBWX', //  维修结果列表		
						key: 'SBWXList',
						cmd: 'getViewState',
						obj: {
							FType: 'SBWX'
						}
					},
					{
						type: 'WXFS', //  维修方法列表
						key: 'WXFSList',
						cmd: 'getViewState',
						obj: {
							FType: 'WXFS'
						}
					}
				]);
			},
			// PDA扫码
			scanHandler(scanData) {
				let that = this;
				console.log(scanData);
				that.DeviceIDChange(scanData.recode, 'pda')
			},
			// 扫码处理判断方法
			DeviceIDChange(res, name) {
				let that = this;

				function startsWithEQRegex(str) {
					return /^EQ/.test(str) || /^SB/.test(str);
				}
				let IsDevice = startsWithEQRegex(res)
				if (IsDevice) {
					var id = res.replace(/^.*?\|/, '')
					that.Request.request('getEquipment', {}, (ret) => {
						if (ret.status == 200) {
							var obj = ret.data.ds.find(item => item.EquipmentID == id)
							var url = `./devicerepairDetail?EquipmentObj=${JSON.stringify(obj)}`
							uni.redirectTo({
								url: url
							});
						}
					})
				}
			},
			deletePic(event) {
				this.DImgs.splice(event.index, 1);
			},
			async afterRead(event) {
				let lists = [].concat(event.file)
				let fileListLen = this.DImgs.length;
				lists.map((item) => {
					this.DImgs.push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})

				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this.DImgs[fileListLen]
					this.DImgs.splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: this.Request.IPAgreement() + this.Request.serverIP() + result
					}))
					fileListLen++
				}
			},

			uploadFilePromise(url) {
				let that = this;
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: that.Request.IPAgreement() + that.Request
							.serverIP() + '/Frame/uploadFile?dirName=' + '现场照片',
						filePath: url,
						name: 'file',
						header: {
							'Content-Type': 'multipart/form-data' // 必须设置
						},
						formData: {
							user: 'test'
						},
						success: (uploadFileRes) => {
							const data = JSON.parse(uploadFileRes.data);
							resolve(data.data)
						}
					});
				})
			},

			// 扫码
			scan() {
				let that = this;
				uni.scanCode({
					success: function(res) {
						that.DeviceIDChange(res.result, 'phone')

					},
					fail: function(fail) {
						console.log(fail);
					}
				});

			},
			// 取消弹框
			confirmClick() {
				this.popup_logout = false
			},
			// 详情数据判断 按钮名称
			addPeriodTypeClick() {
				var that = this
				console.log(that.baseFormData.ProcessNode);
				console.log(that.baseFormData.MaintenanceStatus);
				if (that.baseFormData.ProcessNode == 0) {
					that.buttonTitle = '保存'
				}
				if (that.baseFormData.ProcessNode == 1 && that.baseFormData.MaintenanceStatus == 0) {

					that.buttonTitle = '开始维修'
				} else if (that.baseFormData.ProcessNode == 1 && that.baseFormData.MaintenanceStatus == 1) {

					that.buttonTitle = '结束维修'
				} else if (that.baseFormData.ProcessNode == 2 && that.baseFormData.MaintenanceStatus == 2) {
					that.buttonTitle = '已维修'
				}


				// if (!that.baseFormData.BeginTime) {
				// 	that.buttonTitle = '开始维修'
				// } else if (that.baseFormData.BeginTime) {
				// 	that.buttonTitle = '结束维修'
				// }
				if (that.baseFormData.MaintainEquipmentID && that.baseFormData.BeginTime && that.baseFormData
					.WCTime) {
					that.buttonShow = false
				}
				that.$forceUpdate()
			},
			// 删除子表数据
			trash(index) {
				var that = this
				if (that.buttonShow) {
					that.tableData.splice(index, 1)
					this.$forceUpdate()
				}

			},
			//新增子表数据
			addplus() {
				var that = this
				if (that.buttonShow) {
					var obj = {
						Num: 1,
						ProductPJName: '',
						ProductPJID: null,
						MaintainEquipmentDeID: 0
					}
					that.tableData.push(obj)
					this.$forceUpdate()
				}

			},
			//子表配件筛选
			addproducplname(item, index) {
				var that = this;
				if (that.buttonShow) {
					that.producplnameIndex = index
					that.openBaseScreen('配件', 'radio')
				}

			},
			StateClick(e) {
				var that = this;


				if (that.StateName == 'SBWX') {
					console.log(e.id);
					that.baseFormData.FResult = e.id
					that.baseFormData.FResultName = e.name
					that.$refs.uForm.validateField('FResultName'); // 手动触发 MaintainMan 字段的验证
					that.$forceUpdate()
				} else {

					that.baseFormData.WayName = e.name
					that.baseFormData.Way = e.id
					that.$refs.uForm.validateField('WayName'); // 手动触发 MaintainMan 字段的验证
					that.$forceUpdate()
				}
				this.$forceUpdate()


			},
			// 维修方法
			addWay(str) {
				var that = this;
				if (that.buttonShow) {
					that.StateName = str
					that.StateList = that.WXFSList
					that.StateShow = true
				}

			},
			// 维修结果
			addWay1(str) {
				var that = this;
				if (that.buttonTitle == '结束维修' && that.buttonShow) {
					that.StateName = str
					that.StateList = that.SBWXList
					that.StateShow = true
				}
			},
			addCost() {
				var that = this;
				if (that.buttonTitle == '开始维修') {
					uni.showToast({
						title: '请在结束时填写',
						icon: 'error',
						duration: 2000
					})
				}
			},


			openBaseScreen(str, type) { // 前往筛选页
				let that = this;
				let obj = null;
				let url = '/commonPage/Tool/baseScreen';
				if (that.buttonShow) {
					if (str == '设备') {
						obj = {
							allowClear: false,
							cmd: 'getEquipment',
							type: str,
							ListeningName: 'devicerepairDetail_Choice',
							serverSearch: {
								isPaging: false, //是否分页
								searchKey: 'EquipmentName', //搜索关键词，应包含在param中
								showText: 'EquipmentName', //查询结果显示的字段
								pageIndexStr: 'PageIndex', //分页页码字段，应包含在param中
								ChoiceDataKey: 'EquipmentID',
								ChoiceDataData: that.baseFormData.EquipmentID,
							},
							param: {
								EquipmentName: '',
								PageIndex: 1,
								PageSize: 30
							}
						}
					} else if (str == '维修人员') {
						obj = {
							allowClear: false,
							cmd: 'getEmplByJobName',
							type: str,
							ListeningName: 'devicerepairDetail_Choice',
							serverSearch: {
								isPaging: false, //是否分页
								searchKey: 'SearchKey', //搜索关键词，应包含在param中
								showText: 'EmplName', //查询结果显示的字段
								pageIndexStr: 'PageIndex', //分页页码字段，应包含在param中
								ChoiceDataKey: 'EmplName',
								ChoiceDataData: that.baseFormData.MaintainMan,
							},
							param: {
								SearchKey: '',
								JobName: '',
								PageIndex: 1,
								PageSize: 30
							}
						}

					} else if (str == '配件') {
						obj = {
							allowClear: false,
							cmd: 'getsProductPJ',
							type: str,
							ListeningName: 'devicerepairDetail_Choice',
							serverSearch: {
								isPaging: false, //是否分页
								searchKey: 'SearchKey', //搜索关键词，应包含在param中
								showText: 'ProductPJName', //查询结果显示的字段
								pageIndexStr: 'PageIndex', //分页页码字段，应包含在param中
								ChoiceDataKey: 'ProductPJID',
								ChoiceDataData: that.tableData[that.producplnameIndex].ProductPJID,
							},
							param: {
								SearchKey: '',
								PageIndex: 1,
								PageSize: 30
							}
						}

					}

					this.$store.commit('ChangeAndSetStateData', {
						Name1: 'BaseScreenParm',
						data: obj
					})
					uni.navigateTo({
						url: url
					})
				}
			},
			// 保存
			submit() {
				var that = this
				this.$refs.uForm.validate().then(res => {
					var obj = {
						MaintainEquipmentID: that.baseFormData.MaintainEquipmentID ? that.baseFormData
							.MaintainEquipmentID : 0,
						ApplyForMan: that.baseFormData.ApplyForMan,
						EquipmentID: that.baseFormData.EquipmentID,
						ApplyForTime: that.baseFormData.ApplyForTime,
						BXContent: that.baseFormData.BXContent,
						BillNO: that.baseFormData.BillNO,
						MaintainMan: that.baseFormData.MaintainMan,
						GZCause: that.baseFormData.GZCause,
						Way: that.baseFormData.Way,
						Cost: that.baseFormData.Cost ? that.baseFormData.Cost : 0,
						WCStatus: that.baseFormData.WCStatus,
						FResult: that.baseFormData.FResult ? that.baseFormData.FResult : 0,
						BeginTime: that.baseFormData.BeginTime,
						WCTime: that.baseFormData.WCTime,
						BillDate: that.baseFormData.BillDate,
						FType: 'SBWX',
						Num: that.tableData.map(item => item.Num).join(','),
						ProductPJID: that.tableData.map(item => item.ProductPJID).join(','),
						MaintainEquipmentDeID: that.tableData.map(item => item.MaintainEquipmentDeID)
							.join(','),
						ProductPJName: that.tableData.map(item => item.ProductPJName).join(','),
					}
					console.log(obj);
					that.Request.request('saveMaintainEquipment', obj, function(ret) {
						console.log(ret);
						if (ret.status == 200) {
							that.$refs.uToast.show({
								title: '保存',
								type: 'success',
								message: '保存成功'
							})
							that.queryList(ret.data.ds[0].MaintainEquipmentID)
						}
					})
				}).catch(errors => {
					console.log(errors);
					uni.$u.toast(errors[0].message)
				})
			},

			// 详情
			queryList(id) {
				var that = this
				try {
					that.Request.request('getMaintainEquipmentDetail', {
						MaintainEquipmentID: id
					}, (ret) => {
						console.log(ret);
						ret.data.ds.map((item) => {
							item.ApplyForTime = item.ApplyForTime ? item.ApplyForTime.split('T')[0] : ''
							item.BeginTime = formatDateTime(item.BeginTime)
							item.WCTime = formatDateTime(item.WCTime)
							const dictMappings = {
								MaintenanceStatus: {
									dictKey: 'MJWXS',
									targetField: 'MaintenanceStatusName'
								}
							};
							that.mapDictNamesForItem(item, dictMappings);
						})

						that.baseFormData = ret.data.ds[0]
						that.tableData = ret.data.ds1
						that.addPeriodTypeClick()
						that.$forceUpdate()

					})
				} catch (e) {
					console.log(e)
					this.$utils.hideLoading();
					this.$utils.msg('请求失败请重试')
				}
			},


			// 退出
			leftClick() {
				let routes = getCurrentPages(); //当前页面栈
				let prevPage = routes[routes.length - 2]
				prevPage.$vm.getList()
			}
		}
	}
</script>

<style lang="scss">
	@import "./css/index.scss";

	.buttonView {
		padding: 1%;
		display: flex;
		justify-content: flex-end;
		align-items: center;

		.buttonstyle {
			color: #fff;
			background-color: #51d0d0;
		}
	}

	.content {

		.BottomBox {
			width: 100%;

			padding: 6px 15px;
			border-top: 1px solid #efefef;
			display: flex;
			align-items: center;
			justify-content: flex-end;
			background-color: #fff;


		}
	}

	.AddBottomBox {
		width: 100%;
		display: flex;
		align-items: center;
		padding: 10px;
		justify-content: flex-end;
		/* 关键属性 */
		background-color: #f8f9fa;
		/* 可选背景色 */
		border-top: 1px solid #eee;
		/* 可选顶部边框 */

		.left-buttons {
			display: flex;
			gap: 10px;
			/* 按钮间距 */
		}

		.CancelBtn {
			background-color: #fff;
			color: #51d0d0;
			border: 1px solid #51d0d0;
			min-width: 80px;
			padding: 5px 10px;
			border-radius: 4px;
			font-size: 14px;
			box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
			transition: all 0.3s ease;

			&:active {
				background-color: #e6f7f7;
				transform: translateY(1px);
			}
		}
	}
</style>